package com.atguigu.gmall.product.api;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.result.ResultCodeEnum;
import com.atguigu.gmall.item.vo.CategoryView;
import com.atguigu.gmall.item.vo.SkuInfoDetailVo;
import com.atguigu.gmall.product.entity.SkuInfo;
import com.atguigu.gmall.product.entity.SpuSaleAttr;
import com.atguigu.gmall.product.service.BaseCategory1Service;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.atguigu.gmall.product.service.SkuSaleAttrValueService;
import com.atguigu.gmall.product.service.SpuSaleAttrService;
import com.atguigu.gmall.product.vo.AttrValueConcatVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/api/inner/product")
public class SkuDetailApiController {

    @Autowired
    private BaseCategory1Service baseCategory1Service ;

    @Autowired
    private SkuInfoService skuInfoService ;

    @Autowired
    private SpuSaleAttrService spuSaleAttrService ;

    @Autowired
    private SkuSaleAttrValueService skuSaleAttrValueService ;

    @GetMapping(value = "/findCategoryViewBySkuId/{skuId}")
    public Result<CategoryView> findCategoryViewBySkuId(@PathVariable(value = "skuId") Long skuId) {
        CategoryView categoryView = baseCategory1Service.findCategoryViewBySkuId(skuId) ;
        return Result.build(categoryView , ResultCodeEnum.SUCCESS) ;
    }

    @GetMapping(value = "/findSkuInfoAndImageBySkuId/{skuId}")
    public Result<SkuInfo> findSkuInfoAndImageBySkuId(@PathVariable(value = "skuId") Long skuId) {
        SkuInfo skuInfo = skuInfoService.findSkuInfoAndImageBySkuId(skuId) ;
        return Result.build(skuInfo , ResultCodeEnum.SUCCESS) ;
    }

    @GetMapping(value = "/findSpuSaleAttrAndSaleAttrValue/{skuId}")
    public Result<List<SpuSaleAttr>> findSpuSaleAttrAndSaleAttrValue(@PathVariable(value = "skuId") Long skuId) {
        List<SpuSaleAttr> spuSaleAttrList = spuSaleAttrService.findSpuSaleAttrAndSaleAttrValue(skuId) ;
        return Result.build(spuSaleAttrList , ResultCodeEnum.SUCCESS) ;
    }

    @GetMapping(value = "/findAttrValueConcatBySkuId/{skuId}")
    public Result<List<AttrValueConcatVo>> findAttrValueConcatBySkuId(@PathVariable(value = "skuId") Long skuId) {
        List<AttrValueConcatVo> concatVoList =  skuSaleAttrValueService.findAttrValueConcatBySkuId(skuId) ;
        return Result.build(concatVoList , ResultCodeEnum.SUCCESS) ;
    }

    @GetMapping(value = "/findAllSkuIds")
    public Result<List<Long>> findAllSkuIds() {
        List<Long> skuIds = skuInfoService.findAllSkuIds();
        return Result.build(skuIds , ResultCodeEnum.SUCCESS) ;
    }

    @GetMapping(value = "/findSkuInfoDetail/{skuId}")
    public Result<SkuInfoDetailVo> findSkuInfoDetail(@PathVariable(value = "skuId") Long skuId) {
        SkuInfoDetailVo skuInfoDetailVo =  skuInfoService.findSkuInfoDetail(skuId) ;
        return Result.build(skuInfoDetailVo , ResultCodeEnum.SUCCESS) ;
    }

    @GetMapping(value = "/findSkuInfoBySkuId/{skuId}")
    public Result<SkuInfo> findSkuInfoBySkuId(@PathVariable(value = "skuId") Long skuId) {
        SkuInfo skuInfo = skuInfoService.getById(skuId);
        return Result.ok(skuInfo) ;
    }

}
